{template 'common/header'}
<ul class="nav nav-tabs">
    <li {if $operation=='add' }class="active" {/if}><a href="{php echo $this->createWebUrl('shopping', array('op' => 'goods','operation' =>'add'))}">添加商品</a></li>
    <li {if $operation=='list' }class="active" {/if}><a href="{php echo $this->createWebUrl('shopping', array('op' => 'goods','operation' => 'list'))}">管理商品</a></li>
</ul>
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
        <div class="panel panel-default">
            <div class="panel-heading">
                {if empty($item['id'])}添加商品{else}编辑商品{/if}
            </div>
            <div class="panel-body">
            	<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
					<div class="col-sm-4 col-xs-12">
						<input type="text" name="displayorder" class="form-control" value="{$item['displayorder']}" />
					</div>
				</div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>商品名称</label>
                    <div class="col-sm-4 col-xs-6">
                        <input type="text" name="goodsname" id="goodsname" class="form-control" value="{$item['title']}" />
                    </div>
                </div>
                <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否上架</label>
					<div class="col-sm-4 col-xs-12">
						<label for="isshow1" class="radio-inline"><input type="radio" name="status" value="1" id="isshow1" {if $item['status'] == 1}checked="true"{/if} /> 是</label>
						&nbsp;&nbsp;&nbsp;
						<label for="isshow2" class="radio-inline"><input type="radio" name="status" value="0" id="isshow2"  {if $item['status'] == 0}checked="true"{/if} /> 否</label>
						<span class="help-block"></span>
					</div>
				</div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">商品单位</label>
                    <div class="col-sm-4 col-xs-3">
                        <input type="text" name="unit" id="unit" class="form-control" value="{$item['unit']}" />
                        <span class="help-block">如: 个/件/包</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">商品属性</label>
                    <div class="col-sm-9 col-xs-12">
                        <label for="isrecommand" class="checkbox-inline">
                            <input type="checkbox" name="isrecommand" value="1" id="isrecommand" {if $item[ 'isrecommand']==1 }checked="true" {/if} /> 首页推荐
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span>分类</label>
                    <div class="col-sm-4 col-xs-6">
                        <select class="form-control" style="margin-right:15px;" id="pcate" name="pcate"  >
                            <option value="0">请选择分类</option>
                            {loop $category $row}
                            <option value="{$row['id']}" {if $row['id']==$item[ 'pcate']} selected="selected" {/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">商品图</label>
                    <div class="col-sm-4 col-xs-12">
                        {php echo tpl_form_field_image('thumb', $item['thumb'], '', array('extras' => array('text' => 'readonly')))}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">其他图片</label>
                    <div class="col-sm-6 col-xs-12">
                        {php echo tpl_form_field_multi_image('thumbs',$piclist)}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">商品价格</label>
                    <div class="col-sm-4 col-xs-12">
                        <div class="input-group form-group">
                            <span class="input-group-addon">销售价</span>
                            <input type="text" name="marketprice" id="marketprice" class="form-control" value="{$item['marketprice']}" />
                            <span class="input-group-addon">元</span>
                        </div>
                        <div class="input-group form-group">
                            <span class="input-group-addon">市场价</span>
                            <input type="text" name="productprice" id="productprice" class="form-control" value="{$item['productprice']}" />
                            <span class="input-group-addon">元</span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">库存</label>
                    <div class="col-sm-4 col-xs-12">
                        <div class="input-group">
                            <input type="text" name="total" id="total" class="form-control" value="{$item['total']}" />
                            <span class="input-group-addon">件</span>
                        </div>
                        <span class="help-block">当前商品的库存数量</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">购买积分</label>
                    <div class="col-sm-4 col-xs-12">
                        <div class="input-group">
                            <input type="text" name="credit" id="credit" class="form-control" value="{$item['credit']}" />
                            <span class="input-group-addon">分</span>
                        </div>
                        <p class="help-block">会员购买积分, 如果不填写，则默认为不奖励积分</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">商品详情</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea name="content" class="form-control richtext" cols="70" rows="10">{$item['content']}</textarea>
                    </div>
                </div>
                {if !$user['regionid']}
                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label">选择小区</label>
                        <div class="col-sm-10">
                            <label class="checkbox-inline">  
                                <input type="checkbox" id="checkAll" name="checkAll" data-group="regionid">全部
                            </label>
                          {loop $regions $region}
                            <label class="checkbox-inline">
                              <input type="checkbox" id="regionid" value="{$region['id']}" name='regionid[]' data-group ="regionid" {if @in_array($region['id'], $regs)}checked='checked' {/if}> {$region['city']}{$region['dist']}{$region['title']}
                            </label>
                          {/loop}
                        </div>
                    </div>
                    {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script language='javascript'>
require(['jquery', 'util'], function($, u) {
    $(function() {
        u.editor($('.richtext')[0]);
    });
});
$(function() {
             $("#checkAll").click(function() {

                    var checked = $(this).get(0).checked;
                    var group = $(this).data('group');
                    $("#regionid[data-group='" +group + "']").each(function(){
                        $(this).get(0).checked = checked;
                    })

             });
        });
</script>

{template 'common/footer'}